<?php
/**
 * @version        $Id$
 * @author         master@xuewl.com
 * @copyright      Copyright (c) 2007 - 2014, Chongqing xuewl Information Technology Co., Ltd.
 * @link           http://www.xuewl.com
**/
namespace Sms\Controller;
use \Admin\Controller\InitController;
/**
 * 后台短信平台
 */
class SmsController extends InitController {
	public function _initialize() {
		parent::_initialize();
		$this->db = D('Module');
		$this->sms_report_db = D('SmsReport');
		$this->pagecurr = max(1, I('page', 0, 'intval'));
		$this->pagesize = 10;
		$this->SmsApi = new \Sms\Api\SmsApi();
	}

	public function manage() {
		$page = max(1, (int) I('page'));
		$sms_num = $this->SmsApi->get_num();
		$count = $this->sms_report_db->count();
		$infos = $this->sms_report_db->page($page, 10)->select();
		$pages = page($count, 10);
		include $this->admin_tpl('manage');
	}

	/* 模块配置 */
	public function setting() {
		if (submitcheck('dosubmit')) {
			$setting = serialize($_POST['setting']);
			$this->db->where(array('module' => MODULE_NAME))->setField('setting', $setting);
			setcache('setting', $_POST['setting'], strtolower(MODULE_NAME));
			$this->success('操作成功', U('manage'));
		} else {
			$setting = $this->db->getFieldByModule(MODULE_NAME, 'setting');
			$sms_setting = unserialize($setting);
			$slist = glob(MODULE_PATH.'Api/Driver/*.class.php');
			$files = array();
			if ($slist) {
				foreach ($slist as $file) {
					if (!is_file($file) || !file_exists($file)) continue;
					$filename = basename($file, '.class.php');
					$files[] = $filename;
				}
			}
			include $this->admin_tpl('setting');
		}
	}
}